package project.servlets;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import schronisko.MySQLConnection;

/**
 * Servlet implementation class DeclineAdopt
 */
@WebServlet("/DeclineAdopt")
public class DeclineAdopt extends HttpServlet {
	private static final long serialVersionUID = 1L;
	HttpSession s;
	static int ID;
	static String status = "active";
    /**
     * @see HttpServlet#HttpServlet()
     */
    public DeclineAdopt() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		s = request.getSession();
		PrintWriter out = response.getWriter();
		String ID_adoption=request.getParameter("decline_adoption");
		out.println("<link rel='stylesheet' type='text/css' href='styles/login.css'>");
		
		try{
			MySQLConnection.connect().executeUpdate("UPDATE adoption SET status = 'aborted'  WHERE ID_adoption ="+ID_adoption);
			MySQLConnection.connect().executeUpdate("UPDATE animal SET accessibility = 'available' WHERE ID_animal=(SELECT id_animal from adoption where ID_adoption =" + ID_adoption+")");
    		MySQLConnection.Close();
    		s.setAttribute("decline", 1);
    		response.sendRedirect("worker/decline_adoption.jsp");
	}
		catch (SQLException e){
			e.printStackTrace();
		} 
	}
	}


